﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;

namespace DreametryMIS
{
    public partial class MacroAutomation : Form
    {
       Process p = new Process();
        public MacroAutomation()
        {
            InitializeComponent();
        }

        private void btnbrowser_Click(object sender, EventArgs e)
        {
            DialogResult result = folderBrowse.ShowDialog();
            if (result == DialogResult.OK)
            {
                string[] files = Directory.GetFiles(folderBrowse.SelectedPath);
                txtDir.Text = (folderBrowse.SelectedPath);
            }

        }

        private void btnhome_Click(object sender, EventArgs e)
        {

        }

        private void PbtnSM_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void PbtnSD_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void PbtnTS_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void UbtnSM_Click(object sender, EventArgs e)
        {
            try
            {
                string str = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\MACRO RECORDER\Prep\set up CSV Upload for Supermug.exe";
                p.StartInfo.FileName = str;
                p.Start();
            }
            catch { }

        }

        private void UbtnCC_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void UbtnME_Click(object sender, EventArgs e)
        {
            string str = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\MACRO RECORDER\Prep\set up CSV Upload for MugEmpire.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void UbtnBT_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void UbtnSD_Click(object sender, EventArgs e)
        {
            try
            {
                string str = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\MACRO RECORDER\Prep\set up CSV Upload for SpruchDruck.exe";
                p.StartInfo.FileName = str;
                p.Start();
            }
            catch { }

        }

        private void UbtnHM_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void DbtnBD_Click(object sender, EventArgs e)
        {
            try
            {
                string str = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\MACRO RECORDER\Prep\set up Batch edit - Warning don't open if not in windows this macro will play automatically.exe";
                p.StartInfo.FileName = str;
                p.Start();
            }
            catch
            { }
        }

        private void DbtnSM_Click(object sender, EventArgs e)
        {
            string str = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\MACRO RECORDER\Prep\set up Batch edit for SuperMug - Warning don't open if not in windows this macro will play automatically.exe";
            p.StartInfo.FileName = str;

            if (txtDir.Text == "")
            {
                MessageBox.Show("Add Directory of Folder");
            }
            else
            {
                p.Start();
            }
        }

        private void DbtnSD_Click(object sender, EventArgs e)
        {
            try
            {
                string str = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\MACRO RECORDER\Prep\set up Batch edit for Spruchdruck - Warning don't open if not in windows this macro will play automatically.exe";
                p.StartInfo.FileName = str;
                p.Start();
            }
            catch { }

        }

        private void DbtnME_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void DbtnBT_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void DbtnHF_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void DbtnHM_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void DbtnCC_Click(object sender, EventArgs e)
        {
            string str = @"C:\Program Files\Sublime Text 3\sublime_text.exe";
            p.StartInfo.FileName = str;
            p.Start();
        }

        private void MacroAutomation_Load(object sender, EventArgs e)
        {
            
            labelname.Text = ClassFlow.global_fullname; 
            uploaderFileWatch.EnableRaisingEvents = true;
            ClassFlow.global_count = "SELECT Count(*) FROM EmploeeTask WHERE flow_id = '4' OR flow_id = '6'";
            ClassFlow.unique_SQL_String = "SELECT * FROM EmploeeTask WHERE flow_id = '4' OR flow_id = '6'";
            this.flowControl1.getAll();
            
            taskinprogress.Path = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\"+ClassFlow.global_nickname+ @"\logs\comment";
            //MessageBox.Show(taskinprogress.Path);

        }

        private void btnAI_Click(object sender, EventArgs e)
        {
            getai();
        }

        private void btnPSD_Click(object sender, EventArgs e)
        {
            getpsd();
        }
        private void Ai()
        {
            if (txtSearch.Text == "")
            {
                txtSearch.Text = "Ai";

            }
        }
            public void getai()
        {
            string folder = Uri.EscapeDataString(@"\\server-pc\Dropbox\_____Codiga\");
            string file = txtSearch.Text + "*.ai* type:> .ai";
            string uri = "search:query=" + file + "&crumb=location:" + folder;

            Process.Start(new ProcessStartInfo(uri));
            txtSearch.Clear();
        }

        public void getpsd()
        {
            string folder = Uri.EscapeDataString(@"\\server-pc\Dropbox\_____Codiga\");
            string file = txtSearch.Text + "*.psd* type:> .psd";
            string uri = "search:query=" + file + "&crumb=location:" + folder;

            Process.Start(new ProcessStartInfo(uri));
            txtSearch.Clear();
        }

        private void btnShowTaskFlow_Click(object sender, EventArgs e)
        {
            if (paneluser.Width == 450)
            {
                paneluser.Width = 775;
                paneldesign.Width = 200;
                panelFB.Width = 200;
                panelupload.Width = 200;
                //label2.Text = "FACEBOOK";
                //btnShowTaskFlow.Text = "Collapse Task List";
                //paneluser.Layout.Padding.All = 20;
            }
            else
            {
                paneldesign.Width = 315;
                panelFB.Width = 315;
                panelupload.Width = 315;
                paneluser.Width = 450;
                //label2.Text = "FACEBOOK DRAFT POST:";
                //btnShowTaskFlow.Text = "Expand Task List";
            }
        }

        private void labelsearch_Click(object sender, EventArgs e)
        {

            if (panelsearch.Visible == false)
            {

                labelsearch.Text = "Hide";
                panelsearch.Visible = true;
            }
            else
            {
                panelsearch.Visible = false;
                labelsearch.Text = "Search AI/PSD";
            }
        }

        private void panelsearch_Leave(object sender, EventArgs e)
        {
            panelsearch.Visible = false;
        }

        private void uploaderFileWatch_Changed(object sender, FileSystemEventArgs e)
        {
            notifyIcon1.ShowBalloonTip(5000, "", "New For Batch/Upload", ToolTipIcon.Info);
            this.flowControl1.getAll();
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {

        }

        private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
        {
            String path = e.FullPath;
            String finresult, x;
            String result = System.IO.Path.GetFileName(path);
            //String y = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));


            if (result == "SUPERMUG")
            {
                path = path + @"\SUPERMUG";
                finresult = System.IO.Path.GetFileName(path);
                x = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));
            }else if (result == "Spruck Druck")
            {
                path = path + @"\Spruck Druck";
                finresult = System.IO.Path.GetFileName(path);
                x = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));
            }else
            {

                finresult = System.IO.Path.GetFileName(path);
               x = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));
            }
                notifyIcon1.ShowBalloonTip(5000, "", "New Folder For Batch Editing Added at" + " " + finresult +
                 "                                  " +
                            "                               ", ToolTipIcon.Info);

            listBox1.Items.Add(DateTime.Now + " >>New folder for Batch Editing Added --> at" + finresult);
            this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
        }

       
        private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
        {
            String path = e.FullPath;

            String result = System.IO.Path.GetFileName(path);
            String y = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));


            notifyIcon1.ShowBalloonTip(5000, "", "Folder Changed For Batch Editing Added at" + " " + result +
                 "                                  " +
                            "                               ", ToolTipIcon.Info);

            listBox1.Items.Add(DateTime.Now + " >>>>Folder Changed for Batch Editing Added --> at" + result);
            this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
        }

        private void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
        {
            String path = e.FullPath;

            String result = System.IO.Path.GetFileName(path);
            String y = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));


            notifyIcon1.ShowBalloonTip(5000, "", "Folder Deleted For Batch Editing Added at" + " " + result +
                 "                                  " +
                            "                               ", ToolTipIcon.Info);

            listBox1.Items.Add(DateTime.Now + " >>>>>>Folder Deleted for Batch Editing Added --> at" + result);
            this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
        }

        private void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
        {
            String path = e.FullPath;

            String result = System.IO.Path.GetFileName(path);
            String y = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));


            notifyIcon1.ShowBalloonTip(5000, "", "Folder Renamed For Batch Editing Added at" + " " + result +
                 "                                  " +
                            "                               ", ToolTipIcon.Info);

            listBox1.Items.Add(DateTime.Now + " >>>>>>Folder Renamed for Batch Editing Added --> at " + " " + result);
            this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
        }

        private void taskinprogress_Changed(object sender, FileSystemEventArgs e)
        {
            String path = e.FullPath;
                
                String result = System.IO.Path.GetFileName(path);
                String y = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));
                String x = Path.GetFileNameWithoutExtension(result);

//             if (File.Exists(path))
//             {
//                 File.Delete(path);
//             }
//
            //MessageBox.Show(path);

            notifyIcon1.ShowBalloonTip(5000, "Comment on you Task", x, ToolTipIcon.Info);
        }

        private void taskinprogress_Created(object sender, FileSystemEventArgs e)
        {

            String path = e.FullPath;
            String result = System.IO.Path.GetFileName(path);
            String y = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));
            String x = Path.GetFileNameWithoutExtension(result);

            // if (File.Exists(path))
            //{
            //    File.Delete(path);
            //}

           // MessageBox.Show(x);

            notifyIcon1.ShowBalloonTip(5000, "Comment on you Task", x, ToolTipIcon.Info);
        }


        private void panel1_MouseHover(object sender, EventArgs e)
        {
            panelFB.Visible = false;
            panelupload.Visible = false;
            paneldesign.Visible = false;
            button1.BackColor = Color.WhiteSmoke;
            button2.BackColor = Color.WhiteSmoke;
            button3.BackColor = Color.WhiteSmoke;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
            MainForm form = new MainForm();
            form.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (paneldesign.Visible == false)
            {
                paneldesign.Visible = true;
            }
            else
            {
                paneldesign.Visible = false;
            }
            
                panelFB.Visible = false;
            panelupload.Visible = false;
        
            button1.BackColor = Color.PaleVioletRed;
            button2.BackColor = Color.WhiteSmoke;
            button3.BackColor = Color.WhiteSmoke;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (panelupload.Visible == false)
            {
                panelupload.Visible = true;
            }
            else
            {
                panelupload.Visible = false;
            }
            panelFB.Visible = false;
            paneldesign.Visible = false;
            button1.BackColor = Color.WhiteSmoke;
            button2.BackColor = Color.PaleVioletRed;
            button3.BackColor = Color.WhiteSmoke;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (panelFB.Visible == false)
            {
                panelFB.Visible = true;
            }
            else
            {
                panelFB.Visible = false;
            }

            panelupload.Visible = false;
            paneldesign.Visible = false;
            button1.BackColor = Color.WhiteSmoke;
            button2.BackColor = Color.WhiteSmoke;
            button3.BackColor = Color.PaleVioletRed;
        }

        private void panel1_MouseHover_1(object sender, EventArgs e)
        {
            panelFB.Visible = false;
            panelupload.Visible = false;
            paneldesign.Visible = false;
            button1.BackColor = Color.WhiteSmoke;
            button2.BackColor = Color.WhiteSmoke;
            button3.BackColor = Color.WhiteSmoke;
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            foreach (var item in listBox1.Items)
            {
                writeFile.Main(item.ToString(), @"\\server-pc\Dropbox\_____Codiga\___Uploading Queue (Mug Shots for SM and ME)\save.txt");
            }

            this.Hide();
            MainForm f1 = new MainForm();
            f1.ShowDialog();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                string str = @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\MACRO RECORDER\Prep\set up Batch edit for SuperMug AU - Warning don't open if not in windows this macro will play automatically.exe";
                p.StartInfo.FileName = str;
                p.Start();
            }
            catch { }
        }
    }
    }
    

